home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / utility / 252 / dskpcsrc / clock.mod < prev    next >
Text File  |  1988-02-13  |  26KB  |  820 lines

  1. IMPLEMENTATION MODULE Clock;
  2.  
  3.  
  4.    (*$S-,$T- turn off stack and range checking *) 
  5.  
  6.    FROM SYSTEM IMPORT ADR, ADDRESS;
  7.    IMPORT M2Conversions;
  8.    IMPORT GEMDOS;
  9.    IMPORT GEMVDIbase;
  10.    IMPORT VDIAttribs;
  11.    IMPORT VDIControls;
  12.    IMPORT VDIOutputs;
  13.    IMPORT GEMAESbase;
  14.    IMPORT AESEvents;
  15.    IMPORT AESWindows;
  16.    IMPORT AESApplications;
  17.    IMPORT AESObjects;
  18.    IMPORT AESForms;
  19.    IMPORT AESGraphics;
  20.    IMPORT Configuration;
  21.    IMPORT Text;
  22.    IMPORT TimeDate;
  23.    IMPORT Resource;
  24.    IMPORT Screen;
  25.    IMPORT Icon;
  26.    IMPORT Dialog;
  27.    IMPORT Window;
  28.  
  29.    CONST
  30.       TimeErrorMsg = "[3][ An invalid time was entered. | The correct format is HH:MM.][ OK ]";
  31.       DateErrorMsg = "[3][ An invalid date was entered. | The correct format is DD/MM/YY.][ OK ]";
  32.  
  33.       Bell = 07C;
  34.  
  35.    TYPE
  36.       MsgBufferType = ARRAY [0..7] OF INTEGER;
  37.       String4       = ARRAY [0..4] OF CHAR;
  38.       String4Ptr    = POINTER TO String4;
  39.       String6       = ARRAY [0..6] OF CHAR;
  40.       String6Ptr    = POINTER TO String6;
  41.       String9       = ARRAY [0..9] OF CHAR;
  42.       String9Ptr    = POINTER TO String9;
  43.  
  44.    VAR
  45.       WindowAllocated : BOOLEAN;
  46.       WindowInfo      : Window.Information;
  47.       Time            : CARDINAL;
  48.       Date            : CARDINAL;
  49.       DisplayedTime   : String9;
  50.       DisplayedDate   : String9;
  51.       SmallClock      : BOOLEAN;
  52.       AlarmTime       : CARDINAL;
  53.       AlarmOn         : BOOLEAN;
  54.       SoundAlarm      : BOOLEAN;
  55.       BellCount       : CARDINAL;
  56.       Space           : ARRAY[0..0] OF CHAR;
  57.       Corner          : Screen.Box;
  58.  
  59.    (************************** LOCAL ROUTINE ***************************)
  60.  
  61.    PROCEDURE MinuteChanged;
  62.  
  63.    VAR MsgBuffer : MsgBufferType; 
  64.  
  65.    BEGIN
  66.       MsgBuffer[0] := Resource.MinuteChanged;
  67.       MsgBuffer[1] := Resource.ApplicationId;
  68.       MsgBuffer[2] := 0;
  69.       MsgBuffer[3] := Time DIV 2048;          (* Hours   *)
  70.       MsgBuffer[4] := (Time MOD 2048) DIV 32; (* Minutes *)
  71.       MsgBuffer[5] := 0;                      (* Ignore the seconds *)
  72.       AESApplications.ApplWrite (
  73.          Resource.ApplicationId,
  74.          SIZE (MsgBuffer),
  75.          ADR  (MsgBuffer) );  
  76.    END MinuteChanged;
  77.  
  78.    (************************** LOCAL ROUTINE ***************************)
  79.  
  80.    PROCEDURE DateChanged;
  81.  
  82.    VAR MsgBuffer : MsgBufferType; 
  83.  
  84.    BEGIN
  85.       MsgBuffer[0] := Resource.DateChanged;
  86.       MsgBuffer[1] := Resource.ApplicationId;
  87.       MsgBuffer[2] := 0;
  88.       MsgBuffer[3] := Date MOD 32;            (* Day   *)
  89.       MsgBuffer[4] := (Date MOD 512) DIV 32;  (* Month *)
  90.       MsgBuffer[5] := (Date DIV 512) + 1980;  (* Year  *)
  91.       AESApplications.ApplWrite (
  92.          Resource.ApplicationId,
  93.          SIZE (MsgBuffer),
  94.          ADR  (MsgBuffer) );  
  95.    END DateChanged;
  96.  
  97.    (************************** LOCAL ROUTINE ***************************)
  98.  
  99.    PROCEDURE SetAlarm;
  100.  
  101.    CONST NoFormat = FALSE;
  102.  
  103.    TYPE TedInfoPtrType = POINTER TO Icon.Tedinfo;
  104.  
  105.    VAR
  106.       PMPtr       : Icon.ObjectPtr;
  107.       AMPtr       : Icon.ObjectPtr;
  108.       TimePtr     : Icon.ObjectPtr;
  109.       TedinfoPtr  : TedInfoPtrType;
  110.       TextPtr     : String4Ptr;
  111.       PM          : BOOLEAN;
  112.       AlarmOnPtr  : Icon.ObjectPtr;
  113.       AlarmOffPtr : Icon.ObjectPtr;
  114.       ExitButton  : INTEGER;
  115.  
  116.    BEGIN
  117.       PMPtr      := Icon.GetAddress ( Resource.D5SETALM, Resource.D5PM );
  118.       AMPtr      := Icon.GetAddress ( Resource.D5SETALM, Resource.D5AM );
  119.       TimePtr    := Icon.GetAddress ( Resource.D5SETALM, Resource.D5TIME );
  120.       TedinfoPtr := TedInfoPtrType (TimePtr^.Spec);
  121.       TextPtr    := String4Ptr (TedinfoPtr^.Text);
  122.       LOOP
  123.          DecodeTime ( AlarmTime, NoFormat, TextPtr^ );
  124.          IF (AlarmTime DIV 2048) < 12 THEN
  125.             PMPtr^.State := PMPtr^.State - {Icon.Selected};
  126.             AMPtr^.State := AMPtr^.State + {Icon.Selected};
  127.          ELSE
  128.             PMPtr^.State := PMPtr^.State + {Icon.Selected};
  129.             AMPtr^.State := AMPtr^.State - {Icon.Selected};
  130.          END;
  131.          IF Dialog.Display (
  132.                Resource.D5SETALM,
  133.                Screen.Center,
  134.                Resource.D5TIME ) = Resource.D5OK THEN
  135.             PM := Icon.Selected IN PMPtr^.State;
  136.             IF EncodeTime ( TextPtr^, PM, AlarmTime ) THEN
  137.                AlarmOnPtr := Icon.GetAddress (
  138.                   Resource.D2CLOCK, Resource.D2ALRMON );
  139.                AlarmOnPtr^.Flags := AlarmOnPtr^.Flags - {Icon.HideTree};
  140.                AlarmOffPtr := Icon.GetAddress (
  141.                   Resource.D2CLOCK, Resource.D2ALRMOF );
  142.                AlarmOffPtr^.Flags := AlarmOffPtr^.Flags + {Icon.HideTree};
  143.                AlarmOn := TRUE;
  144.                IF WindowAllocated THEN
  145.                   Window.Redraw ( WindowInfo.Id, WindowInfo.Borders );
  146.                END;
  147.                EXIT;
  148.             ELSE
  149.                ExitButton := AESForms.FormAlert ( 1, TimeErrorMsg );
  150.             END;
  151.          ELSE
  152.            EXIT;
  153.          END;
  154.       END;
  155.    END SetAlarm;
  156.  
  157.    (************************** LOCAL ROUTINE ***************************)
  158.  
  159.    PROCEDURE ClockDraw ( Region : Screen.Box );
  160.  
  161.       (* Note:  This procedure is invoked only when the clock *)
  162.       (*        is full size.                                 *)
  163.  
  164.    CONST UseFormat = TRUE;
  165.  
  166.    BEGIN
  167.       DecodeTime ( Time, UseFormat, DisplayedTime ); 
  168.       GEMDOS.GetDate ( Date );
  169.       DecodeDate ( Date, UseFormat, DisplayedDate );
  170.       Icon.Display ( Resource.D2CLOCK, 0, Region );
  171.    END ClockDraw;
  172.  
  173.    (************************** LOCAL ROUTINE ***************************)
  174.  
  175.    PROCEDURE SmallClockDraw ( ShowTime : BOOLEAN );
  176.  
  177.    CONST
  178.       ClippingOn = 1;
  179.       Hollow     = 0;
  180.       UseFormat  = TRUE;
  181.  
  182.    VAR
  183.       FillStyle : INTEGER;
  184.       PxyArray  : GEMVDIbase.PxyArrayType;
  185.  
  186.    BEGIN
  187.       FillStyle   := VDIAttribs.SetFillInteriorStyle (
  188.          Screen.VirtualHandle, Hollow );
  189.       PxyArray[0] := Corner.Origin.X;
  190.       PxyArray[1] := Corner.Origin.Y;
  191.       PxyArray[2] := Corner.Origin.X + Corner.Size.Width - 1;
  192.       PxyArray[3] := Corner.Origin.Y + Corner.Size.Height - 1;
  193.       VDIControls.SetClipping (
  194.          Screen.VirtualHandle, ClippingOn, PxyArray );
  195.       VDIOutputs.FillRectangle ( Screen.VirtualHandle, PxyArray );
  196.       IF ShowTime THEN
  197.          DecodeTime ( Time, UseFormat, DisplayedTime );
  198.          VDIOutputs.GraphicText (
  199.             Screen.VirtualHandle,
  200.             Corner.Origin.X,
  201.             Corner.Origin.Y + Screen.CharacterArea.Height - 1,
  202.             DisplayedTime );
  203.       END;
  204.    END SmallClockDraw;
  205.  
  206.    (************************** LOCAL ROUTINE ***************************)
  207.  
  208.    PROCEDURE AlarmOff;
  209.  
  210.    VAR ObjectPtr : Icon.ObjectPtr;
  211.  
  212.    BEGIN
  213.       ObjectPtr  := Icon.GetAddress ( Resource.D2CLOCK, Resource.D2ALRMON );
  214.       ObjectPtr^.Flags := ObjectPtr^.Flags + {Icon.HideTree};
  215.       ObjectPtr  := Icon.GetAddress ( Resource.D2CLOCK, Resource.D2ALRMOF );
  216.       ObjectPtr^.Flags := ObjectPtr^.Flags - {Icon.HideTree};
  217.       AlarmOn    := FALSE;
  218.       SoundAlarm := FALSE;
  219. (*    TimerResolution := 15000;                           6/6/87 - SMN *)
  220.       TimerResolution := 5000;   (* 5 seconds *)       (* 6/6/87 - SMN *)
  221.    END AlarmOff;
  222.  
  223.    (********************************************************************)
  224.  
  225.    PROCEDURE Initialize;
  226.  
  227.    VAR
  228.       TimePtr : Icon.ObjectPtr;
  229.       DatePtr : Icon.ObjectPtr;
  230.  
  231.    BEGIN
  232.       Corner.Size.Width  := Screen.CharacterArea.Width * 9;
  233.       Corner.Size.Height := Screen.CharacterArea.Height;
  234.       Corner.Origin.X    := Screen.WorkSpace.Size.Width - Corner.Size.Width;
  235.       Corner.Origin.Y    := 0;
  236.       TimePtr := Icon.GetAddress ( Resource.D2CLOCK, Resource.D2TIME );
  237.       TimePtr^.Spec := ADR ( DisplayedTime );
  238.       DatePtr := Icon.GetAddress ( Resource.D2CLOCK, Resource.D2DATE );
  239.       DatePtr^.Spec := ADR ( DisplayedDate );
  240.  
  241.       (*---- Prompt the user to set the time and date -----------------*)
  242.  
  243.       IF (Configuration.ShowTime[0] <> 'N') AND
  244.          (Configuration.ShowTime[0] <> 'n') THEN
  245.          AESEvents.EventTimer ( 3000,0 );  (* Allow time for windows to open *)
  246.          AESWindows.WindowUpdate ( GEMAESbase.BeginUpdate );
  247.          SetTime;
  248.          SetDate;
  249.          AESWindows.WindowUpdate ( GEMAESbase.EndUpdate );
  250.       ELSE
  251.          GEMDOS.SetDate ( TimeDate.GetDate () );
  252.          GEMDOS.SetTime ( TimeDate.GetTime () );
  253.       END;
  254.    END Initialize;
  255.  
  256.    (********************************************************************)
  257.  
  258.    PROCEDURE DayPeriod () : BOOLEAN;
  259.  
  260.    VAR Hours : CARDINAL;
  261.  
  262.    BEGIN
  263.       Hours := Time DIV 2048;
  264.       RETURN ((Hours >= 8) AND (Hours < 17)); 
  265.    END DayPeriod;
  266.  
  267.    (********************************************************************)
  268.  
  269.    PROCEDURE EveningPeriod () : BOOLEAN;
  270.  
  271.    VAR Hours : CARDINAL;
  272.  
  273.    BEGIN
  274.       Hours := Time DIV 2048;
  275.       RETURN ((Hours >= 17) AND (Hours < 23)); 
  276.    END EveningPeriod;
  277.  
  278.    (********************************************************************)
  279.  
  280.    PROCEDURE NightPeriod () : BOOLEAN;
  281.  
  282.    VAR Hours : CARDINAL;
  283.  
  284.    BEGIN
  285.       Hours := Time DIV 2048;
  286.       RETURN ((Hours >= 23) OR (Hours < 8)); 
  287.    END NightPeriod;
  288.  
  289.    (********************************************************************)
  290.  
  291.    PROCEDURE DecodeTime ( Time              : CARDINAL;
  292.                           UseFormat         : BOOLEAN;
  293.                           VAR FormattedTime : ARRAY OF CHAR ); 
  294.  
  295.    VAR
  296.       PM      : BOOLEAN;             
  297.       Hours   : CARDINAL;
  298.       Minutes : CARDINAL;
  299.       Buffer  : String9;
  300.       Success : BOOLEAN;
  301.  
  302.    BEGIN
  303.       Hours := Time DIV 2048;
  304.       IF Hours > 23 THEN
  305.          FormattedTime[0] := CHR (0);
  306.       ELSE
  307.          Minutes := (Time MOD 2048) DIV 32;
  308.          IF Minutes > 59 THEN
  309.             FormattedTime[0] := CHR (0);
  310.          ELSE
  311.             IF Hours = 0 THEN
  312.                PM     := FALSE;
  313.                Hours  := 12;
  314.             ELSIF Hours < 12 THEN
  315.                PM := FALSE; 
  316.             ELSE
  317.                PM := TRUE;
  318.                IF Hours > 12 THEN
  319.                   Hours := Hours - 12;
  320.                END;
  321.             END;
  322.             M2Conversions.ConvertCardinal ( Hours, 2, FormattedTime );
  323.             IF UseFormat THEN
  324.                FormattedTime[2] := ':';
  325.                FormattedTime[3] := CHR (0);
  326.             END;
  327.             M2Conversions.ConvertCardinal ( Minutes, 2, Buffer );
  328.             IF Buffer[0] = ' ' THEN
  329.                Buffer[0] := '0';  
  330.             END;
  331.             Success := Text.ConcatString (
  332.                FormattedTime, Buffer, FormattedTime );
  333.             IF UseFormat THEN
  334.                IF PM THEN
  335.                   Success := Text.ConcatString (
  336.                      FormattedTime, " PM ", FormattedTime );
  337.                ELSE
  338.                   Success := Text.ConcatString (
  339.                      FormattedTime, " AM ", FormattedTime );
  340.                END;
  341.             END;
  342.          END;
  343.       END;
  344.    END DecodeTime;
  345.  
  346.    (********************************************************************)
  347.  
  348.    PROCEDURE DecodeDate ( Date              : CARDINAL;
  349.                           UseFormat         : BOOLEAN;
  350.                           VAR FormattedDate : ARRAY OF CHAR );
  351.  
  352.    VAR                                  
  353.       Day     : CARDINAL;
  354.       Month   : CARDINAL;
  355.       Year    : CARDINAL;
  356.       Buffer  : String9;
  357.       Success : BOOLEAN;
  358.  
  359.    BEGIN
  360.       Year  := (Date DIV 512) + 80;  (* Only adjust last two digits *)
  361.       IF Year > 99 THEN
  362.          Year := Year - 100;
  363.       END;
  364.       Month := (Date MOD 512) DIV 32;
  365.       Day   := Date MOD 32;
  366.       M2Conversions.ConvertCardinal ( Month, 2, FormattedDate );
  367.       IF UseFormat THEN
  368.          FormattedDate[2] := '/';
  369.          FormattedDate[3] := CHR (0);
  370.       END;
  371.       M2Conversions.ConvertCardinal ( Day, 2, Buffer );
  372.       IF Buffer[0] = ' ' THEN
  373.          Buffer[0] := '0';
  374.       END;
  375.       Success := Text.ConcatString ( FormattedDate, Buffer, FormattedDate );
  376.       IF UseFormat THEN
  377.          FormattedDate[5] := '/';
  378.          FormattedDate[6] := CHR (0);
  379.       END;
  380.       M2Conversions.ConvertCardinal ( Year, 2, Buffer );
  381.       IF Buffer[0] = ' ' THEN
  382.          Buffer[0] := '0';
  383.       END;
  384.       Success := Text.ConcatString ( FormattedDate, Buffer, FormattedDate );
  385.    END DecodeDate;
  386.  
  387.    (********************************************************************)
  388.  
  389.    PROCEDURE EncodeTime ( VAR FormattedTime : ARRAY OF CHAR;
  390.                           PM                : BOOLEAN;
  391.                           VAR Time          : CARDINAL ) : BOOLEAN;
  392.  
  393.    VAR                                  
  394.       Hours      : CARDINAL;
  395.       Minutes    : CARDINAL;
  396.       Buffer     : String9;
  397.       Success    : BOOLEAN;
  398.  
  399.    BEGIN
  400.       Success := Text.SliceString ( FormattedTime, 0, 1, Buffer );
  401.       M2Conversions.ConvertToCardinal ( Buffer, Success, Hours );
  402.       IF (NOT Success) OR (Hours < 1) OR (Hours > 12) THEN
  403.          Time := 0;
  404.          RETURN (FALSE);
  405.       END;
  406.       IF PM AND (Hours < 12) THEN
  407.          Hours := Hours + 12;
  408.       ELSIF (NOT PM) AND (Hours = 12) THEN
  409.          Hours := 0;
  410.       END;
  411.       Success := Text.SliceString ( FormattedTime, 2, 3, Buffer );
  412.       M2Conversions.ConvertToCardinal ( Buffer, Success, Minutes );
  413.       IF (NOT Success) OR (Minutes > 59) THEN
  414.          Time := 0;
  415.          RETURN (FALSE);
  416.       END;
  417.       Time := (Hours * 2048) + (Minutes * 32);
  418.       RETURN (TRUE);
  419.    END EncodeTime;
  420.  
  421.    (********************************************************************)
  422.  
  423.    PROCEDURE EncodeDate ( VAR FormattedDate : ARRAY OF CHAR;
  424.                           VAR Date          : CARDINAL ) : BOOLEAN;
  425.  
  426.    VAR                                  
  427.       Day      : CARDINAL;
  428.       Month    : CARDINAL;
  429.       Year     : CARDINAL;
  430.       Buffer   : String9;
  431.       Success  : BOOLEAN;
  432.  
  433.    BEGIN
  434.       Success := Text.SliceString ( FormattedDate, 0, 1, Buffer );
  435.       M2Conversions.ConvertToCardinal ( Buffer, Success, Month );
  436.       IF (NOT Success) OR (Month < 1) OR (Month > 12) THEN
  437.          Date := 0; 
  438.          RETURN (FALSE);
  439.       END;
  440.       Success := Text.SliceString ( FormattedDate, 2, 3, Buffer );
  441.       M2Conversions.ConvertToCardinal ( Buffer, Success, Day );
  442.       IF (NOT Success) OR (Day < 1) OR (Day > 31) THEN
  443.          Date := 0;
  444.          RETURN (FALSE);
  445.       END;
  446.       Success := Text.SliceString ( FormattedDate, 4, 5, Buffer );
  447.       M2Conversions.ConvertToCardinal ( Buffer, Success, Year );
  448.       IF NOT Success THEN
  449.          Date := 0;
  450.          RETURN (FALSE);
  451.       END;
  452.       IF Year < 85 THEN         (* Since only two digits are entered, *)
  453.          Year := Year + 100;    (* adjust year if year is 0 to 84.    *)
  454.       END;
  455.       Date := ((Year - 80) * 512) + (Month * 32) + Day;
  456.       RETURN (TRUE);
  457.    END EncodeDate;
  458.  
  459.    (********************************************************************)
  460.  
  461.    PROCEDURE SetTime;
  462.  
  463.    CONST NoFormat = FALSE;
  464.  
  465.    TYPE TedInfoPtrType = POINTER TO Icon.Tedinfo;
  466.  
  467.    VAR
  468.       SystemTime : CARDINAL;
  469.       PMPtr      : Icon.ObjectPtr;
  470.       AMPtr      : Icon.ObjectPtr;
  471.       TimePtr    : Icon.ObjectPtr;
  472.       TedinfoPtr : TedInfoPtrType;
  473.       TextPtr    : String4Ptr;
  474.       PM         : BOOLEAN;
  475.       ExitButton : INTEGER;
  476.  
  477.    BEGIN
  478.       PMPtr   := Icon.GetAddress ( Resource.D3SETTIM, Resource.D3PM );
  479.       AMPtr   := Icon.GetAddress ( Resource.D3SETTIM, Resource.D3AM );
  480.       TimePtr := Icon.GetAddress ( Resource.D3SETTIM, Resource.D3TIME );
  481.       TedinfoPtr := TedInfoPtrType (TimePtr^.Spec);
  482.       TextPtr    := String4Ptr (TedinfoPtr^.Text);
  483.       LOOP
  484.          SystemTime := TimeDate.GetTime ();
  485.          DecodeTime ( SystemTime, NoFormat, TextPtr^ );
  486.          IF (SystemTime DIV 2048) < 12 THEN
  487.             PMPtr^.State := PMPtr^.State - {Icon.Selected};
  488.             AMPtr^.State := AMPtr^.State + {Icon.Selected};
  489.          ELSE
  490.             PMPtr^.State := PMPtr^.State + {Icon.Selected};
  491.             AMPtr^.State := AMPtr^.State - {Icon.Selected};
  492.          END;
  493.          IF Dialog.Display (
  494.                Resource.D3SETTIM,
  495.                Screen.Center,
  496.                Resource.D3TIME ) = Resource.D3OK THEN
  497.             PM := Icon.Selected IN PMPtr^.State;
  498.             IF EncodeTime ( TextPtr^, PM, Time ) THEN
  499.                GEMDOS.SetTime ( Time );
  500.                MinuteChanged;
  501.                IF WindowAllocated THEN
  502.                   Window.Redraw ( WindowInfo.Id, WindowInfo.Borders );
  503.                END;
  504.                EXIT;
  505.             ELSE
  506.                ExitButton := AESForms.FormAlert ( 1, TimeErrorMsg );
  507.             END;
  508.          ELSE
  509.             EXIT;
  510.          END;
  511.       END (* LOOP *);
  512.    END SetTime;
  513.  
  514.    (********************************************************************)
  515.  
  516.    PROCEDURE SetDate;
  517.  
  518.    CONST NoFormat = FALSE;
  519.  
  520.    TYPE TedInfoPtrType = POINTER TO Icon.Tedinfo;
  521.  
  522.    VAR
  523.       SystemDate : CARDINAL;
  524.       DatePtr    : Icon.ObjectPtr;
  525.       TedinfoPtr : TedInfoPtrType;
  526.       TextPtr    : String6Ptr;
  527.       ExitButton : INTEGER;
  528.  
  529.    BEGIN
  530.       DatePtr    := Icon.GetAddress ( Resource.D4SETDAT, Resource.D4DATE );
  531.       TedinfoPtr := TedInfoPtrType (DatePtr^.Spec);
  532.       TextPtr    := String6Ptr (TedinfoPtr^.Text);
  533.       LOOP
  534.          SystemDate := TimeDate.GetDate ();
  535.          DecodeDate ( SystemDate, NoFormat, TextPtr^ );
  536.          IF Dialog.Display (
  537.                Resource.D4SETDAT,
  538.                Screen.Center,
  539.                Resource.D4DATE ) = Resource.D4OK THEN
  540.             IF EncodeDate ( TextPtr^, Date ) THEN
  541.                GEMDOS.SetDate ( Date );
  542.                DateChanged;
  543.                IF WindowAllocated THEN
  544.                   Window.Redraw ( WindowInfo.Id, WindowInfo.Borders );
  545.                END;
  546.                EXIT;
  547.             ELSE
  548.                ExitButton := AESForms.FormAlert ( 1, DateErrorMsg );
  549.             END;
  550.          ELSE
  551.             EXIT;
  552.          END;
  553.       END (* LOOP *);
  554.    END SetDate;
  555.  
  556.    (********************************************************************)
  557.  
  558.    PROCEDURE OwnsWindow ( WindowId : INTEGER ) : BOOLEAN;
  559.  
  560.    BEGIN
  561.       IF WindowAllocated THEN
  562.          RETURN (WindowId = WindowInfo.Id);
  563.       ELSE
  564.          RETURN (FALSE);
  565.       END;
  566.    END OwnsWindow;
  567.  
  568.    (********************************************************************)
  569.  
  570.    PROCEDURE Open;
  571.  
  572.    CONST EraseTime = FALSE;
  573.  
  574.    VAR
  575.       WindowRegion      : Screen.Box;
  576.       WindowName        : Text.String80;
  577.       VirtualRegionSize : Window.Area;
  578.  
  579.    BEGIN
  580.       IF WindowAllocated THEN
  581.          Window.Top ( WindowInfo.Id );
  582.       ELSE
  583.          Icon.GetRegion ( Resource.D2CLOCK, 0, WindowRegion );
  584.          WindowRegion.Origin.X := 
  585.             Screen.Center.Origin.X - (WindowRegion.Size.Width DIV 2);
  586.          WindowRegion.Origin.Y := 
  587.             Screen.Center.Origin.Y - (WindowRegion.Size.Height DIV 2);
  588.          VirtualRegionSize.Width  :=
  589.             Window.Pixel (WindowRegion.Size.Width);
  590.          VirtualRegionSize.Height :=
  591.             Window.Pixel (WindowRegion.Size.Height);
  592.          IF SmallClock THEN
  593.             SmallClockDraw ( EraseTime );
  594.             AESGraphics.GrafGrowBox (
  595.                Corner.Origin.X,
  596.                Corner.Origin.Y,
  597.                Corner.Size.Width,
  598.                Corner.Size.Height,
  599.                WindowRegion.Origin.X,
  600.                WindowRegion.Origin.Y,
  601.                WindowRegion.Size.Width,
  602.                WindowRegion.Size.Height );
  603.             SmallClock := FALSE;
  604.          END;
  605.          IF Window.Open (
  606.                Screen.Center,
  607.                Window.InformationPtr (ADR (WindowInfo)),
  608.                " Clock ",
  609.                "",          (* No information line *)
  610.                WindowRegion,
  611.                VirtualRegionSize,
  612.                GEMAESbase.Name +
  613.                GEMAESbase.Closer +
  614.                GEMAESbase.Fuller +
  615.                GEMAESbase.Mover,
  616.                0, 1,        (* White Background *)
  617.                Resource.D2CLOCK,
  618.                ClockDraw ) THEN
  619.             WindowAllocated := TRUE;
  620.          ELSE
  621.             Window.Unavailable;
  622.             WindowAllocated := FALSE;
  623.          END;
  624.       END;
  625.    END Open;
  626.  
  627.    (********************************************************************)
  628.  
  629.    PROCEDURE Close;
  630.  
  631.    BEGIN
  632.       IF SoundAlarm THEN
  633.          AlarmOff;
  634.       END;
  635.       IF WindowAllocated THEN
  636.          Window.Close ( WindowInfo.Id, Screen.Center );
  637.          WindowAllocated := FALSE;
  638.       END;
  639.    END Close;
  640.  
  641.    (********************************************************************)
  642.  
  643.    PROCEDURE ProcessTimerEvent;
  644.  
  645.    CONST ShowTime = TRUE;
  646.  
  647.    VAR SystemTime : CARDINAL;
  648.  
  649.    BEGIN
  650.       IF AlarmOn AND SoundAlarm THEN
  651.          GEMDOS.ConOut ( Bell );
  652.          IF BellCount > 0 THEN
  653.             DEC ( BellCount );
  654.          END;
  655.       END;
  656.       GEMDOS.GetTime ( SystemTime );
  657.       SystemTime := SystemTime DIV 32 * 32;   (* Get rid of seconds *)
  658.       IF SystemTime <> Time THEN
  659.          IF SystemTime < Time THEN
  660.             GEMDOS.GetDate ( Date );
  661.             DateChanged;
  662.          END;
  663.          Time := SystemTime;
  664.          MinuteChanged;
  665.          IF AlarmOn AND (Time >= AlarmTime) AND (NOT SoundAlarm) THEN
  666.             Open ();   (* Either open a clock window or top it *)
  667.             SoundAlarm := TRUE;
  668.             BellCount  := 3;
  669.             TimerResolution := 1000;  (* 1 seconds *)
  670.          ELSIF SmallClock THEN
  671.             SmallClockDraw ( ShowTime );
  672.          ELSIF WindowAllocated THEN
  673.             Window.Redraw ( WindowInfo.Id, WindowInfo.Borders );
  674.          END;
  675.       END;
  676.    END ProcessTimerEvent;
  677.  
  678.    (********************************************************************)
  679.  
  680.    PROCEDURE ProcessMessageEvent ( VAR MsgBuffer : ARRAY OF INTEGER ); 
  681.  
  682.    CONST ShowTime = TRUE;
  683.  
  684.    VAR WindowRegion : Screen.Box;
  685.  
  686.    BEGIN
  687.       IF MsgBuffer[0] = GEMAESbase.AccessoryClose THEN
  688.          IF SmallClock THEN
  689.             SmallClockDraw ( ShowTime );
  690.          ELSIF WindowAllocated THEN
  691.             Window.Close ( 0, Screen.Center );
  692.             WindowAllocated := FALSE;
  693.          END;
  694.  
  695.       ELSIF MsgBuffer[0] = GEMAESbase.WindowFulled THEN
  696.          IF SoundAlarm AND (BellCount = 0) THEN
  697.             AlarmOff;
  698.          END;
  699.          WindowRegion := WindowInfo.Borders;
  700.          Close ();
  701.          AESGraphics.GrafShrinkBox (
  702.             Corner.Origin.X,
  703.             Corner.Origin.Y,
  704.             Corner.Size.Width,
  705.             Corner.Size.Height,
  706.             WindowRegion.Origin.X,
  707.             WindowRegion.Origin.Y,
  708.             WindowRegion.Size.Width,
  709.             WindowRegion.Size.Height );
  710.          SmallClockDraw ( ShowTime );
  711.          SmallClock := TRUE;
  712.  
  713.       ELSE
  714.          IF SoundAlarm AND (BellCount = 0) THEN
  715.             AlarmOff;
  716.             Icon.Display ( Resource.D2CLOCK, Resource.D2ALRMOF, WindowInfo.Borders );
  717.          END;
  718.          GEMDOS.ConOut ( Bell );
  719.       END;
  720.    END ProcessMessageEvent;
  721.  
  722.    (********************************************************************)
  723.  
  724.    PROCEDURE ProcessButtonEvent ( MouseButton : INTEGER;
  725.                                   ModifierKey : INTEGER;
  726.                                   Clicks      : INTEGER );
  727.  
  728.    VAR
  729.       MouseLocation : Screen.PixelCoordinate;
  730.       MouseState    : INTEGER;
  731.       KeyboardState : INTEGER;
  732.       Object        : INTEGER;
  733.       ObjectPtr     : Icon.ObjectPtr;
  734.  
  735.    BEGIN
  736.       IF SoundAlarm AND (BellCount = 0) THEN
  737.          AlarmOff;
  738.          Icon.Display ( Resource.D2CLOCK, Resource.D2ALRMOF, WindowInfo.Borders );
  739.       END;
  740.       AESGraphics.GrafMouseKeyboardState (
  741.          MouseLocation.X,
  742.          MouseLocation.Y,
  743.          MouseState,
  744.          KeyboardState );
  745.       IF Icon.Find ( Resource.D2CLOCK, MouseLocation, Object ) THEN
  746.  
  747.          IF Object = Resource.D2TIME THEN
  748.             IF Clicks = 2 THEN
  749.                SetTime;
  750.             END;
  751.  
  752.          ELSIF Object = Resource.D2DATE THEN
  753.             IF Clicks = 2 THEN
  754.                SetDate;
  755.             END;
  756.  
  757.          ELSIF Object = Resource.D2ALRMON THEN
  758.             IF Clicks = 1 THEN
  759.                AlarmOff;
  760.                Icon.Display (
  761.                   Resource.D2CLOCK,
  762.                   Resource.D2ALRMOF,
  763.                   WindowInfo.Borders );
  764.             ELSE
  765.                SetAlarm ();
  766.             END;
  767.  
  768.          ELSIF Object = Resource.D2ALRMOF THEN
  769.             IF Clicks = 1 THEN
  770.                ObjectPtr := Icon.GetAddress (
  771.                   Resource.D2CLOCK, Resource.D2ALRMON );
  772.                ObjectPtr^.Flags := ObjectPtr^.Flags - {Icon.HideTree};
  773.                ObjectPtr := Icon.GetAddress (
  774.                   Resource.D2CLOCK, Resource.D2ALRMOF );
  775.                ObjectPtr^.Flags := ObjectPtr^.Flags + {Icon.HideTree};
  776.                AlarmOn   := TRUE;
  777.                Icon.Display (
  778.                   Resource.D2CLOCK,
  779.                   Resource.D2ALRMON,
  780.                   WindowInfo.Borders );
  781.             ELSE
  782.                SetAlarm ();
  783.             END;
  784.  
  785.          ELSE
  786.             GEMDOS.ConOut ( Bell );
  787.          END;
  788.       END;         
  789.    END ProcessButtonEvent;
  790.  
  791.    (********************************************************************)
  792.  
  793.    PROCEDURE ProcessKeyboardEvent ( Key         : INTEGER;
  794.                                     ModifierKey : INTEGER );
  795.  
  796.    BEGIN
  797.       IF SoundAlarm AND (BellCount = 0) THEN
  798.          AlarmOff;
  799.          Icon.Display ( Resource.D2CLOCK, Resource.D2ALRMOF, WindowInfo.Borders );
  800.       END;
  801.       GEMDOS.ConOut ( Bell );
  802.    END ProcessKeyboardEvent;
  803.  
  804.  
  805. BEGIN
  806. (* TimerResolution := 15000;                              6/6/87 - SMN *)
  807.    TimerResolution := 5000;   (* 5 seconds *)          (* 6/6/87 - SMN *)
  808.    WindowAllocated := FALSE;
  809.    Time            := 0;
  810.    Date            := 0;
  811.    DisplayedTime   := "";
  812.    DisplayedDate   := "";
  813.    SmallClock      := FALSE;
  814.    AlarmTime       := 0;
  815.    AlarmOn         := FALSE;
  816.    SoundAlarm      := FALSE;
  817.    Space           := " ";
  818. END Clock.
  819.  
  820.